package com.hzw.saas.api.product.enums;

import java.util.Objects;

/**
 * 订单状态
 *
 * @author zzl
 * @since 01/21/2021
 */
public enum OrderStatus {

    CONFIRM_SUCCESS(1, "已确认"),
    CONFIRM_FAIL(2, "确认失败"),
    PAY_PROGRESS(10, "待付款"),
    PAY_SUCCESS(11, "付款成功"),
    REFUND_PROGRESS(20, "退款中"),
    REFUND_SUCCESS(21, "退款成功"),
    REFUND_FAIL(22, "退款失败"),
    CANCEL(30, "取消"),
    CLOSE(90, "关闭"),
    UNKNOWN(99, "未知");

    private final Integer value;
    private final String text;

    public Integer value() {
        return value;
    }

    public String text() {
        return text;
    }

    OrderStatus(Integer value, String text) {
        this.value = value;
        this.text = text;
    }

    public static String text(Integer value) {
        for (OrderStatus orderStatus : OrderStatus.values()) {
            if (Objects.equals(orderStatus.value, value)) {
                return orderStatus.text();
            }
        }
        return null;
    }

    public static OrderStatus instance(Integer value) {
        for (OrderStatus orderStatus : OrderStatus.values()) {
            if (Objects.equals(orderStatus.value, value)) {
                return orderStatus;
            }
        }
        return null;
    }
}
